package server

import (
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"logistics/demo"
	"logistics/oauth2"
	"os"
)

func Start() {
	work, _ := os.Getwd()
	viper.SetConfigName("server")
	viper.SetConfigType("yml")
	viper.AddConfigPath(work + "/conf")
	viper.ReadInConfig()
	g := gin.Default()
	auth := g.Group("/auth")
	{
		auth.GET("/token", oauth2.TokenRequest)
		auth.GET("/credentials", oauth2.Credentials)
	}
	de := g.Group("/demo")
	{
		de.GET("/message", demo.Message)
	}
	de1 := g.Group("/demo1")
	{
		var c *gin.Context
		//权限认证中间件
		de1.Use(oauth2.AuthValidate(c))
		de1.GET("/message", demo.Message1)
	}
	g.Run(":" + viper.GetString("server.port"))
}
